<template>
	<view class="">
		<view class="" style="height: 300rpx;">
			
		</view>
		<button type="primary" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber"
			style="margin-top:32rpx;background-color:#EBBE87;font-weight:600;width: 702rpx;border-radius: 50rpx; color: #844902;">绑定手机号</button>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				num:0,
			}
		},
		onLoad(options) {
			this.num = Number(options.backPageNum);
		},
		methods:{
			decryptPhoneNumber(e) {
				var _this = this;
				if (e.detail.errMsg == 'getPhoneNumber:ok') {
					uni.login({
						success(res) {
							let {
								iv,
								cloudID,
								code,
								encryptedData
							} = e.detail
							_this.$request({
								url: 'user/phoneDecrypt',
								method: 'POST',
								data: {
									iv: iv,
									encryptedData: encryptedData,
									code: res.code
								}
							}).then(res => {
								if(_this.num==1){
									_this.$store.commit("setData", uni.getStorageSync('tempUserInfo'));
									_this.$store.commit("setRecordData",uni.getStorageSync('tempStatistics'));
									_this.$store.commit("setIsLogin", true);
									_this.$store.dispatch('getCarList')
									_this.$store.dispatch('getCollection')
									_this.$store.dispatch('getBrowse')
									uni.removeStorageSync('tempUserInfo');
									uni.removeStorageSync('tempStatistics');
									uni.navigateBack({})
								}else{
									_this.$store.commit("setData", uni.getStorageSync('tempUserInfo'));
									_this.$store.commit("setIsLogin", true)
									_this.$store.dispatch('getCarList')
									_this.$store.dispatch('getCollection')
									_this.$store.dispatch('getBrowse')
									uni.removeStorageSync('tempUserInfo');
									uni.navigateBack({
										delta: 3
									})
								}
							})
						}
					})
			
					this.$wanlshop.msg('授权成功')
			
				} else {
					this.$wanlshop.msg('授权失败')
				}
			},
		}
	}
</script>

<style>
</style>